﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using com.paypal.soap.api;
using ASPDotNetSamples;

public partial class Admin_GetTransactionDetails : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void GetButton_Click(object sender, EventArgs e)
    {
       // Response.Redirect(Util.AppendTransactionId("TransactionDetails.aspx", this.transactionID.Text));
        TransactionSearch.Visible = false;  
        this.DataBind();
    }
        public GetTransactionDetailsResponseType GetTransactionDetailsResponse
    {
        get
        {
            return (GetTransactionDetailsResponseType)this.PayPalResponse;
        }
    }

    //protected override void OnPreRender(EventArgs e)
    //{
    //    base.OnPreRender(e);
    //    this.DataBind();
    //}

  

    private string GrossAmount
    {
        get
        {
            return GetTransactionDetailsResponse.PaymentTransactionDetails.PaymentInfo.GrossAmount.Value;
        }
    }

    private CurrencyCodeType Currency
    {
        get
        {
            return GetTransactionDetailsResponse.PaymentTransactionDetails.PaymentInfo.GrossAmount.currencyID;
        }
    }

    public string TransactionIDResponse
    {
        get
        {
            return GetTransactionDetailsResponse.PaymentTransactionDetails.PaymentInfo.TransactionID;
        }
    }

    public override void DataBind()
    {
        if (this.transactionID.Text != null)
        {
            Global.is3token = true;
            Session["stage"] = "SandBox";
            SetProfile.SessionProfile = SetProfile.CreateAPIProfile(Constants.API_USERNAME, Constants.API_PASSWORD, Constants.API_SIGNATURE, "", "", "", "", "SandBox", "");
            PayPalAPI api = new PayPalAPI();
            this.PayPalResponse = api.GetTransactionDetails(this.transactionID.Text);
            this.TransactionDetailsPlaceHolder.Visible = this.HasValidTransaction();
            if (HasValidTransaction())
            {
                TransactionSearch.Visible = true;  
                this.TransactionDetailsPlaceHolder.DataBind();
            }
            HideLinksForOrder(this.transactionID.Text.StartsWith("O-"));
        }
    }

    private void HideLinksForOrder(bool hide)
    {

       
    }

    private bool HasValidTransaction()
        {
        return this.PayPalResponse != null && this.GetTransactionDetailsResponse.PaymentTransactionDetails.PayerInfo.Payer != null;
    }
}
